package main

import (
	"log"
)

type DNSError struct {
	Err         string // description of the error
	Name        string // name looked for
	Server      string // server used
	IsTimeout   bool   // if true, timed out; not all timeouts set this
	IsTemporary bool   // if true, error is temporary; not all errors set this
}

func (e *DNSError) Error() string {
	if e == nil {
		return "<nil>"
	}
	s := "lookup " + e.Name
	if e.Server != "" {
		s += " on " + e.Server
	}
	s += ": " + e.Err
	return s
}

type errorString struct {
	s string
}

func (e *errorString) Error() string {
	return e.s
}
func New(text string) error {
	return &errorString{text}
}

// error 类实现....
func Sqrt(f float64) (float64, error) {
	if f < 0 {
		return 0, New("math: square root of negative number")
	}
	return 0, nil
}
func main() {
	dnsError := new(DNSError)
	dnsError.Server = "127.0.0.1"
	dnsError.Name = "dns"
	dnsError.Err = "dns invalid"
	err := dnsError.Error()
	log.Println(err)

	///////
	_, err1 := Sqrt(-1)
	if err1 != nil {
		log.Println(err1)
	}

}
